# -*- coding: utf-8 -*-
# @Author : 17
# @Time    : 2024/4/24 14:11
# @File    : bugs_clear_notice.py
from mysql.mysql_conn import MysqlDB


def get_project_ids() -> list:
    """ 获取项目 ID """
    sql = "select * from zt_product where acl = 'open' and deleted = '0';"
    project_data = MysqlDB().fetch_all(sql)
    ids = []
    for i in project_data:
        ids.append(i['id'])
    return ids


def get_bugs() -> list:
    BUGS = []
    for i in get_project_ids():
        """查询所有项目中未关闭的bug（不包含延期处理）"""
        sql = "select a.title as title,a.PRJ as PRJ , b.realName , c.name, b.mobile from zt_bug as a " \
              "inner join zt_user as b inner join zt_product as c where a.assignedTo = b.account " \
              "and a.product = c.id and a.product = {0} and a.deleted = '0' and a.status != 'closed' " \
              "and resolution != 'postponed'GROUP BY a.assignedTo".format(i)

        # 统计出该项目中未关闭的bug对应的负责人，以及未关闭的总数
        bugsCount = MysqlDB().fetch_all(sql)
        BUGS.append(bugsCount)
    return BUGS

